/**
 * 热点舆情组件
 * 
 * 作用：展示热门舆情数据列表
 * 使用：在首页分析区域展示热点舆情信息
 * 数据：接收包含id、title、platform、heat_value和sentiment_type属性的数组
 * 特点：按热度排序展示舆情信息，显示平台来源和情感类型
 */

<script setup lang="ts">
import { computed } from 'vue'

// 定义属性
const props = defineProps<{
  data: Array<{
    id: number;
    title: string;
    platform: string;
    heat_value: number;
    sentiment_type: number;
  }>
}>()

// 根据情感类型获取标签类型
const getSentimentType = (type: number) => {
  switch (type) {
    case 1:
      return {
        label: '正面',
        type: 'success'
      }
    case -1:
      return {
        label: '负面',
        type: 'danger'
      }
    default:
      return {
        label: '中性',
        type: 'info'
      }
  }
}

// 格式化热度值
const formatHeatValue = (value: number) => {
  if (value >= 1000) {
    return (value / 1000).toFixed(1) + 'k'
  }
  return value
}

// 处理点击舆情项
const handleItemClick = (id: number) => {
  window.open(`/sentiment/${id}`, '_blank')
}
</script>

<template>
  <div class="hot-sentiments">
    <div v-if="data.length === 0" class="empty-data">
      <el-empty description="暂无热点舆情数据" />
    </div>
    
    <el-scrollbar height="250px" v-else>
      <div class="sentiment-list">
        <div 
          v-for="item in data" 
          :key="item.id" 
          class="sentiment-item"
          @click="handleItemClick(item.id)"
        >
          <div class="sentiment-content">
            <div class="sentiment-title">{{ item.title }}</div>
            <div class="sentiment-meta">
              <span class="platform">
                <el-icon><el-icon-connection /></el-icon> {{ item.platform }}
              </span>
              <el-tag 
                :type="getSentimentType(item.sentiment_type).type" 
                size="small"
                effect="light"
              >
                {{ getSentimentType(item.sentiment_type).label }}
              </el-tag>
            </div>
          </div>
          <div class="heat-value">
            <div class="heat-label">热度</div>
            <div class="heat-number">{{ formatHeatValue(item.heat_value) }}</div>
          </div>
        </div>
      </div>
    </el-scrollbar>
  </div>
</template>

<style scoped>
.hot-sentiments {
  height: 100%;
  width: 100%;
}

.empty-data {
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sentiment-list {
  padding: 0 5px;
}

.sentiment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 10px;
  border-bottom: 1px solid #f0f0f0;
  transition: all 0.3s;
  cursor: pointer;
}

.sentiment-item:last-child {
  border-bottom: none;
}

.sentiment-item:hover {
  background-color: #f9f9f9;
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sentiment-content {
  flex: 1;
  min-width: 0;
}

.sentiment-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 5px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sentiment-meta {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: #999;
}

.platform {
  display: inline-flex;
  align-items: center;
  margin-right: 10px;
}

.platform .el-icon {
  margin-right: 4px;
  font-size: 12px;
}

.heat-value {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  margin-left: 10px;
}

.heat-label {
  font-size: 12px;
  color: #999;
}

.heat-number {
  font-size: 16px;
  font-weight: bold;
  color: #ff9800;
}
</style> 